// 创建点标记
export const createMarker = (map: any, AMapObj: any, x: any, y: any) => {
  //  点标记
  const markerContent =
      `<div class="custom-content-marker">
            <img src="https://a.amap.com/jsapi_demos/static/demo-center/icons/dir-via-marker.png">
            <div class="close-btn">X</div>
          </div>`
  const position = new AMapObj.LngLat(x, y); //Marker 经纬度
  const marker = new AMapObj.Marker({
    position: position,
    content: markerContent, //将 html 传给 content
    offset: new AMapObj.Pixel(-13, -30), //以 icon 的 [center bottom] 为原点
  });
  // 添加点标记
  map.add(marker);
  // 未关闭按钮添加点击事件
  const closeBtn = document.querySelector(".close-btn")
  if (closeBtn) {
    closeBtn.addEventListener('click', () => {
      clearMarker(map, marker); // 移除 marker
    });
  }
}

// 移除点标记
export const clearMarker = (map:any, marker: any) => {
  console.log("移除点标记")
  map.remove(marker); //清除 marker
}